<template>
  <div>
    <el-form :inline="true">
      <el-form-item>
<!--        <el-button type="primary"-->
<!--                   icon="el-icon-plus" @click="handleAdd">-->
<!--          添加-->
<!--        </el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      border
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        width="50"
        label="id">
      </el-table-column>
      <el-table-column
        prop="nickName"
        label="名字">
      </el-table-column>
      <el-table-column
        prop="telephone"
        label="号码">
      </el-table-column>
      <el-table-column
        prop="serviceType"
        label="服务类型">
        <template slot-scope="{row}">
          {{getServiceType(row)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="telephone"
        label="在线评测">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            @click="viewScore(row)"
            type="primary">
            查看在线评测
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="remarks"
        width="400"
        label="备注">
      </el-table-column>

<!--      <el-table-column-->
<!--        label="操作">-->
<!--        <template slot-scope="{row}">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="success"-->
<!--            @click="update(row)">编辑</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="danger"-->
<!--            @click="del(row)">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <el-pagination
      background
      :current-page="current"
      style="margin-top: 20px;"
      @current-change="currentChange"
      layout="prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {deepClone} from "@/utils";
import tinymceComponent from '@/components/tinymce'
import { getAnli,addAnli,delAnli,editAnli} from "@/api/anli";
import { getYuyue,getZz,getScore } from "@/api/yuyue";

export default {
  name: "index",
  components:{
    tinymceComponent
  },
  data() {
    return {
      current:1,
      tableData:[],
      total:0,
      dialogFormVisible:false,
      bianji:false,
      form:{
        "patientName": "",
        "picCover": "",
        "patientSex": "",
        "patientAge": "",
        "courseTime": "",
        "clinicalDiagnosis": "",
        "treatmentDiary": "",
        "fileId": 1
      },
      sex:[{title:"男"},{title:"女"}],
      zz:[]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getServiceType({serviceType}){
      const t = this.zz.filter(({dictCode}) => dictCode===serviceType)
      return t[0]?t[0].dictLabel:'aa'
    },
    async getList(){
      const res = await getZz()
      console.log(res.data.records)
      this.zz = res.data.records
      getYuyue(this.current).then(res=>{
        console.log(res.data)
        this.tableData = res.data.records
        this.total = res.data.total
        this.current = res.data.current
      })
    },
    del(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await delAnli({
          id:row.id,
          fileId:row.fileId
        })
        console.log(res)
        this.$message.success('操作成功')
        await this.getList()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    update(row){
      this.bianji = true
      this.form = deepClone(row)
      this.dialogFormVisible = true
    },
    currentChange(page){
      this.current = page
      this.getList()
    },
    async submit(){
      if (this.bianji){
        await editAnli(this.form)
      }else {
        await addAnli(this.form)
      }
      this.$message.success('操作成功！')
      this.dialogFormVisible = false
      await this.getList()
    },
    handleAdd(){
      this.bianji = false
      this.dialogFormVisible = true
    },
    diaClose(){
      this.$refs.ff.resetFields()
      this.form = {
        treatmentDiary: ""
      }
    },
    handleAvatarSuccess(res){
      console.log(res)
      this.form.picCover = res.data.fileUrl
      this.form.fileId = res.data.id
    },
    viewScore(row){
      console.log(row)
      getScore(row.id).then(res=>{
        console.log(res)
        this.$router.push(`/my/exam/result/${res.data.id}/${row.id}`)
      })
    }
  }
}
</script>

<style scoped>
>>>.el-dialog__wrapper{
  z-index: 999 !important;
}
</style>
